package com.capgemini.scaffold.user;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.capgemini.scaffold.common.ResponseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("用户管理")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @ApiOperation("新增用户")
    @PostMapping("/add")
    public ResponseBean<User> add(@RequestBody User user) {
        return ResponseBean.success(userService.add(user));
    }

    @ApiOperation("根据id删除用户")
    @DeleteMapping("/delete/{id}")
    public ResponseBean<Integer> deleteById(@PathVariable("id") Integer id) {
        return ResponseBean.success(userService.delete(id));
    }

    @ApiOperation("更新用户信息")
    @PutMapping("/update")
    public ResponseBean<Integer> update(@RequestBody User user) {
        return ResponseBean.success(userService.update(user));
    }

    @ApiOperation("根据id获取用户信息")
    @GetMapping("/get/{id}")
    public ResponseBean<User> get(@PathVariable("id") Integer id) {
        return ResponseBean.success(userService.get(id));
    }

    @ApiOperation("用户查询接口")
    @PostMapping("/queryUser")
    public ResponseBean<List<User>> queryUser(@RequestBody UserReq req) {
        return ResponseBean.success(userService.queryUser(req));
    }

    @ApiOperation("分页查询用户信息")
    @PostMapping("/queryUserPage")
    public ResponseBean<IPage<User>> queryUserPage(@RequestBody UserReq req) {
        return ResponseBean.success(userService.queryUserPage(req));
    }
}
